package com.yanqu.road.server.cmd.systemgroup;

import com.yanqu.road.entity.systemgroup.common.SystemServerGroupWeekData;
import com.yanqu.road.logic.pb.ServerSystemGroupPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.union.SystemGroupMatchProto;
import com.yanqu.road.server.CrossBattleServer;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.systemgroup.Cross2SystemWeekGroupMatchMgr;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = CrossProtocol.C_CROSS_SYSTEM_MATCH_GROUP_SYNC, desc = "同步分组信息到活动服")
public class ServerSystemMatchGroupSyncCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        SystemGroupMatchProto.Cross3NotifyMatchGroupToActivityMsg msg = SystemGroupMatchProto.Cross3NotifyMatchGroupToActivityMsg.parseFrom(packet.getBytes());
        if(msg.getCrossId() != CrossBattleServer.getInstance().getServerId()){
            return;
        }
        List<SystemServerGroupWeekData> groupWeekDataList = new ArrayList<>();
        for (SystemGroupMatchProto.ServerSystemMatchGroupTemp groupTemp : msg.getGroupList()) {
            groupWeekDataList.add(ServerSystemGroupPb.parseMatchGroupTemp(groupTemp));
        }

        Cross2SystemWeekGroupMatchMgr.syncMatchGroup(msg.getWeekId(), msg.getSystemId(), groupWeekDataList);
    }

    @Override
    public void sendData() {

    }
}
